<% form_tag( url_for(:action=>"save_parts"),  { :onsubmit => "return validate(this);" }) do -%>
  <fieldset class="column-right2" id="agrupacion">
    <legend >Listado de Partes Asignadas</legend>
<br/>
<table  id="list_selected" style="font-size: 9px;">
  <thead>
  <tr>
  <th>Código</th>
  <th>Nombre de Patrimonio</th>
  <th>Acciones</th>
  </tr>
</thead>
  <tbody>
<% @assignments_list.each do |cultural_heritage_cultural_heritage| %>
    <tr >
      <td class="national_registration_code"><p style="font-size: 9px"><%= cultural_heritage_cultural_heritage.nationalRegistrationCode %></p></td>
      <td class="name"><p style="font-size: 9px"><%= cultural_heritage_cultural_heritage.name %></p></td>
    <td>
      <a href="#" cultural-heritage-id='<%= cultural_heritage_cultural_heritage.id %>' class="js_unlink_cultural_heritage" title="Desasociar">
         <img border="0" title="Desasociar" src="/images/navi/0045-badge-circle-direction-left-16-ns.png" alt="Desasociar" />
      </a>
      <input type="hidden" name="cultural_heritage_selected[]" value='<%= cultural_heritage_cultural_heritage.id %>'/>
    </td>
    </tr>
<% end %>
    </tbody>
</table>
<br></br>
  <p><label>Codigo de Nuevo Patrimonio:</label><%= text_field_tag "cultural_heritage_code" %></p>
  <%= hidden_field_tag "cultural_heritage_id",@cultural_heritage_cultural_heritage.id  %>  
  <%= submit_tag "Guardar" , :confirm => 'Esta seguro de unir las partes definitivamente?' %>
<% end %>
</fieldset>
<br></br>
<script type="text/javascript">
  // form validation function //
  function validate(form) {
    //input
    var nationalRegistrationCode = form.cultural_heritage_code.value;        
    var codeRegex = /^[0-9A-Z]+$/;
    if ((document.getElementById("list_selected").rows.length)<2) {      
      inlineMsg('list_selected','Debe seleccionarse al menos un patrimonio',3);
      return false;
    }
    if(nationalRegistrationCode == "") {      
      inlineMsg('cultural_heritage_code','Debe ingresar un Codigo de Registro Nacional para el Patrimonio Cultural.',3);
      return false;
    }
    if (!nationalRegistrationCode.match(codeRegex)) {
      inlineMsg('cultural_heritage_code','Debe de ingresar un Codigo de Registro Nacional válido (Mayusculas y numeros, sin espacios).',3);
      return false;
    }    
  }
</script>